<template>
	<view>
		<u-mask :show="showMask"></u-mask>
		<view class="head">
			<u-navbar :is-back="false" :border-bottom="false"></u-navbar>
			<u-tabs :list="list" :is-scroll="false" :current="current" @change="change"></u-tabs>
		</view>
		
		<swiper :current="current" @change="change" style="width: 100vw;" :style="{height:'calc(100vh - ' + height +'px )'}">
			<swiper-item>
				<km1 :orderRecord="km1OrderRecord" :count="km1Count" :examRecord="km1ExamRecord"/>
			</swiper-item>
			<swiper-item>
				<km4 :orderRecord="km4OrderRecord" :count="km4Count" :examRecord="km4ExamRecord"/>
			</swiper-item>
		</swiper>
	</view>
</template>

<script>
	import km1 from './km1.vue'
	import km4 from './km4.vue'
	export default {
		components:{
			km1,
			km4
		},
		data() {
			return {
				current:0,
				list: [{
					name: '科目一'
				}, {
					name: '科目四'
				}],
				height:100,
				km1:{},
				km4:{},
				km1OrderRecord:0,
				km1Count:0,
				km1ExamRecord:0,
				km4OrderRecord:0,
				km4Count:0,
				km4ExamRecord:0
			}
		},
		onLoad() {
			//等待app.vue获取数据
			let that = this;
			let setInter = setInterval(()=>{
			    if(that.vuex_user.hasOwnProperty('openid')){
			        that.init();
					clearInterval(setInter) 
					that.showMask = false
			    }
			},100)
			this.initView();
		},
		methods: {
			change(index) {
				if(isNaN(index))
					this.current = index.detail.current;
				else 
					this.current = index;
				
			},
			init(){
				let model = this.vuex_user.model;
				let that = this;
				this.$u.api.getRecord({km:model+'1'}).then(res => {
					that.km1OrderRecord = res.data.data.orderRecord
					that.km1Count = res.data.count
					that.km1ExamRecord = res.data.data.examRecord
				});
				this.$u.api.getRecord({km:model+'4'}).then(res => {
					that.km4OrderRecord = res.data.data.orderRecord
					that.km4Count = res.data.count
					that.km4ExamRecord = res.data.data.examRecord
				});
			},
			initView(){
				let that = this;
				uni.createSelectorQuery().in(this).select('.head').boundingClientRect(result => { 
					that.height = result.height;
				}).exec();
			}
		}
	}
</script>

<style>

</style>
